﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data.Linq;
using System.Web.UI.WebControls;
using mmoss.orm;
using mmoss.classes;

public partial class Login : System.Web.UI.Page
{

    private string message
    {
        get { return (Request.QueryString["msg"] == null ? "" : Request.QueryString["msg"].ToString()); }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        btnLogin.Click += new EventHandler(btnLogin_Click);
        if (message != "")
        {
            lblError.Text = message+"<br/>";
        }
    }

    void btnLogin_Click(object sender, EventArgs e)
    {
        //check for user
        User l_user = dbConn.db.Users.ValidateLogin(
            txtUserName.Text.Trim()
            , txtPassword.Text.Trim()
            , PermissionTypes.crm_write.ToString());
        if (l_user!=null)
        {
            Session["crmUser"]=l_user;
            //hard-code list for now, should intercept on running lists
            Session["crmListID"] = 1;
            Response.Redirect("crmList.aspx");
        }
        else
        {
            lblError.Text = "Invalid Username/Password<br/>";
        }
            
    }
}